package com.health.fragment.focusgroup;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.FWMYDPJActivity;
import com.health.NovaApplication;
import com.health.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.focusgroup.GXYActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.ARCHIVE_GENERALCONDITION;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CD_DRUGCONDITION;
import com.health.tablebean.CD_HYPERTENSIONFOLLOWUP;
import com.health.tools.GlobalConts;
import com.health.tools.SPUtil;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import static com.novabluetooth.services.ktxyj.Constants.DEFAULT_IDCARD;

/**
 * 重点人群-- 高血压--随访
 *
 * @author nova
 */
public class GXY_SfFragment extends NovaFragment implements onFragmentSave, OnClickListener {
    private static final String TAG = "GXY_SfFragment";

    private View cqsf2View = null;
    private FDbManager fdbmanger = null;

    // ------------------------------基本信息-----------------------------
    private EditTextWithDate ed_date;
    private NiceSpinner ed_sfys;// 随访医生
    private NiceSpinner nice_spinner_szfs;// 选择随诊方式

    private MyGridView gd_zz;// 症状

    private EditText ed_xy;// 血压
    private Button btn_choose_xy;

    private EditText ed_xl;// 心率
    private EditText ed_tz;// 体重
    private Button btn_choose_tz;// 选择体重
    private EditText ed_xcsfmb_tz;// 下次随访目标 体重
    private Button btn_choose_xl;


    private EditText ed_tzzs;// 体质指数
    private EditText ed_height;// 身高
    private EditText ed_tzzs_sf;// 体质指数 随访
    private EditText ed_qt;// 其他
    private EditText ed_rxyl;// 日吸烟量
    private EditText ed_xcsfmb_xy;// 日吸烟量 随访
    private EditText ed_ryjl;// 日饮酒量

    private EditText ed_xcsfmb_yj;// 日饮酒量 随访
    private EditText ed_yd_zq;// 运动周
    private EditText ed_yd_min;// 运动分钟
    private EditText ed_xcsfmb_yd_zq;// 运动周
    private EditText ed_xcsfmb_yd_min;// 运动分钟
    private NiceSpinner nice_spinner_syqk;// 摄盐情况
    private NiceSpinner nice_spinner_xcsfmb;// 摄盐情况
    private NiceSpinner nice_spinner_xltz;// 摄盐情况
    private NiceSpinner nice_spinner_zyxw;// 遵医行为

    private EditText ed_fzjc;// 辅助检查
    private NiceSpinner nice_spinner_fyycx;// 服药依从性
    private MyGridView gd_ywblfy;// 药物不良反应

    private NiceSpinner nice_spinner_clsffl;// 此类随访分类
    private NiceSpinner nice_spinner_clsff2;// 此类随访分类

    private AutoCompleteTextView ed_ywmc1;// 药物名称1
    private NiceSpinner nice_spinner_dw1;// 药物单位1
    private NiceSpinner nice_spinner_dw2;// 药物单位2
    private NiceSpinner nice_spinner_dw3;// 药物单位3
    private NiceSpinner nice_spinner_dw11;// 药物单位1
    private NiceSpinner nice_spinner_dw22;// 药物单位2
    private NiceSpinner nice_spinner_dw33;// 药物单位3
    private NiceSpinner nice_spinner_dwqt;// 药物单位其他
    private EditText ed_ywmc1_day;// 每日 day
    private EditText ed_ywmc1_mg;// 每次 mg

    private AutoCompleteTextView ed_ywmc2;// 药物名称2

    private EditText ed_ywmc2_day;// 每日 day
    private EditText ed_ywmc2_mg;// 每次 mg
    private AutoCompleteTextView ed_ywmc3;// 药物名称3

    private EditText ed_ywmc3_day;// 每日 day
    private EditText ed_ywmc3_mg;// 每次 mg

    private AutoCompleteTextView ed_qtyw;// 药物名称3

    private EditText ed_qtyw_day;// 每日 day
    private EditText ed_qtyw_mg;// 每次 mg
    //用药调整
    private AutoCompleteTextView ed_ywmc11;// 药物名称1
    private EditText ed_ywmc11_day;// 每日 day
    private EditText ed_ywmc11_mg;// 每次 mg

    private AutoCompleteTextView ed_ywmc22;// 药物名称2

    private EditText ed_ywmc22_day;// 每日 day
    private EditText ed_ywmc22_mg;// 每次 mg

    private AutoCompleteTextView ed_ywmc33;// 药物名称3

    private EditText ed_ywmc33_day;// 每日 day
    private EditText ed_ywmc33_mg;// 每次 mg

    private EditText ed_zzyy;// 转诊原因
    private EditText ed_jgkb;// 机构及科别
    private EditTextWithDate ed_xcsfsj;// 下次随访时间

    private EditText lxrdh;//联系人及电话

    TextView name_text;
    TextView number_text;

    private RadioGroup jieguo;//结果
    private RadioButton daowei;
    private RadioButton budaowei;
    private EditText sfysqm;//随访医生签名
    private EditText jmqm;//居民签名
    private EditText bz;//备注
    String isDaiWei = "0";


    // ----------------------------------------------------------------------
    private RadioButtonAdapter adapter_ywblfy = null;

    private CheckBoxAdapter adapter_zz = null;

    private List<BD_DD_INFO> sy_list = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> xcsfmb_list = new ArrayList<BD_DD_INFO>();

    private List<BD_DD_INFO> xltz_list = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> zyxw_list = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> ywycx_list = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> szfs_list = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> ccsffl_list = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> ccsffl_list2 = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> ywdw_list = new ArrayList<BD_DD_INFO>();
    private List<BD_DD_INFO> ywdw_list2 = new ArrayList<BD_DD_INFO>();
    public ARCHIVE_BASEINFO userInfo;
    private CD_HYPERTENSIONFOLLOWUP followUp;
    String strWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "'";
    private CD_HYPERTENSIONFOLLOWUP readFollowup;
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    // 定义字符串数组，作为提示的文本
    String[] gxy_yws = new String[]{"缬沙坦片", "复方利血平片", "复方利血平氨苯蝶啶片", "硝苯地平缓释片", "硝苯地平控释片", "卡托普利片", "尼莫地平片",
            "马来酸依那普利片", "苯磺酸氨氯地平片", "吲达帕胺片", "依那普利片", "心普利片", "心胺利片", "硝苯地平片", "尼群地平片",};
    List<ARCHIVE_GENERALCONDITION> ags;

    @Override
    public View findViews(LayoutInflater inflater) {
        fdbmanger = NovaApplication.fdbmanger;
        userInfo = NovaApplication.getUserInfo();
        ags = fdbmanger.findAllByWhere(ARCHIVE_GENERALCONDITION.class, "IDCARD = '" + userInfo.getIDCARD() + "'");
        cqsf2View = inflater.inflate(R.layout.gxy_sfxx, null);
        initViews(cqsf2View);
        GlobalConts.setMaxLength(13, ed_xy);// 血压
        GlobalConts.setMaxLength(3, ed_xl, ed_rxyl, ed_xcsfmb_xy, ed_ryjl, ed_xcsfmb_yj, ed_yd_zq, ed_yd_min,
                ed_xcsfmb_yd_zq, ed_xcsfmb_yd_min);// 心率
        GlobalConts.setMaxLength(50, ed_qt, ed_fzjc, ed_zzyy, ed_jgkb);// 其他
        GlobalConts.setMaxLength(35, ed_ywmc1, // 药物名称1
                ed_ywmc2, // 药物名称2
                ed_ywmc3, // 药物名称3
                ed_qtyw);// 药物名称3
        GlobalConts.setMaxLength(35, ed_ywmc11, // 药物名称1
                ed_ywmc22, // 药物名称2
                ed_ywmc33, // 药物名称3
                ed_qtyw);// 药物名称3

        return cqsf2View;
    }

    /**
     * 初始化布局
     *
     * @param v
     * @author 王婷婷
     * @date 2015年12月21日 上午11:10:55
     */
    private void initViews(View v) {
        lxrdh = v.findViewById(R.id.lxrjdh);
        jieguo = v.findViewById(R.id.jieguo);
        daowei = v.findViewById(R.id.daowei);
        budaowei = v.findViewById(R.id.budaowei);
        sfysqm = v.findViewById(R.id.sfysqm);
        jmqm = v.findViewById(R.id.jmqm);
        bz = v.findViewById(R.id.bz);

        ed_date = (EditTextWithDate) v.findViewById(R.id.ed_date);
        ed_sfys = (NiceSpinner) v.findViewById(R.id.ed_sfys);
        nice_spinner_szfs = (NiceSpinner) v.findViewById(R.id.nice_spinner_szfs);
        name_text = v.findViewById(R.id.name_text);
        number_text = v.findViewById(R.id.number_text);
        name_text.setText("姓名：" + NovaApplication.getUserInfo().getCUSTOMERNAME());
        if (TextUtils.isEmpty(NovaApplication.getUserInfo().getCUSTOMERID())) {

        } else {
            number_text.setText("编号：" + NovaApplication.getUserInfo().getCUSTOMERID());
        }
        gd_zz = (MyGridView) v.findViewById(R.id.gd_zz);

        ed_xy = (EditText) v.findViewById(R.id.ed_xy);
        btn_choose_xy = (Button) v.findViewById(R.id.btn_choose_xy);
        btn_choose_xl = (Button) v.findViewById(R.id.btn_choose_xl);

        ed_xl = (EditText) v.findViewById(R.id.ed_xl);
        ed_tz = (EditText) v.findViewById(R.id.ed_tz);
        btn_choose_tz = (Button) v.findViewById(R.id.btn_choose_tz);
        ed_xcsfmb_tz = (EditText) v.findViewById(R.id.ed_xcsfmb_tz);

        ed_tzzs = (EditText) v.findViewById(R.id.ed_tzzs);
        ed_height = (EditText) v.findViewById(R.id.ed_height);
        ed_tzzs_sf = (EditText) v.findViewById(R.id.ed_tzzs_sf);
        ed_qt = (EditText) v.findViewById(R.id.ed_qt);
        ed_rxyl = (EditText) v.findViewById(R.id.ed_rxyl);
        ed_xcsfmb_xy = (EditText) v.findViewById(R.id.ed_xcsfmb_xy);
        ed_ryjl = (EditText) v.findViewById(R.id.ed_ryjl);

        ed_xcsfmb_yj = (EditText) v.findViewById(R.id.ed_xcsfmb_yj);
        ed_yd_zq = (EditText) v.findViewById(R.id.ed_yd_zq);
        ed_yd_min = (EditText) v.findViewById(R.id.ed_yd_min);
        ed_xcsfmb_yd_zq = (EditText) v.findViewById(R.id.ed_xcsfmb_yd_zq);
        ed_xcsfmb_yd_min = (EditText) v.findViewById(R.id.ed_xcsfmb_yd_min);
        nice_spinner_syqk = (NiceSpinner) v.findViewById(R.id.nice_spinner_syqk);
        nice_spinner_xcsfmb = (NiceSpinner) v.findViewById(R.id.nice_spinner_xcsfmb);
        nice_spinner_xltz = (NiceSpinner) v.findViewById(R.id.nice_spinner_xltz);
        nice_spinner_zyxw = (NiceSpinner) v.findViewById(R.id.nice_spinner_zyxw);

        ed_fzjc = (EditText) v.findViewById(R.id.ed_fzjc);
        nice_spinner_fyycx = (NiceSpinner) v.findViewById(R.id.nice_spinner_fyycx);
        gd_ywblfy = (MyGridView) v.findViewById(R.id.gd_ywblfy);

        nice_spinner_clsffl = (NiceSpinner) v.findViewById(R.id.nice_spinner_clsffl);
        nice_spinner_clsff2 = v.findViewById(R.id.nice_spinner_clsff2);

        ed_ywmc1 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc1);

        ed_ywmc1_day = (EditText) v.findViewById(R.id.ed_ywmc1_day);
        ed_ywmc1_mg = (EditText) v.findViewById(R.id.ed_ywmc1_mg);

        ed_ywmc2 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc2);
        ed_ywmc2_day = (EditText) v.findViewById(R.id.ed_ywmc2_day);
        ed_ywmc2_mg = (EditText) v.findViewById(R.id.ed_ywmc2_mg);
        ed_ywmc3 = (AutoCompleteTextView) v.findViewById(R.id.ed_ywmc3);
        ed_ywmc3_day = (EditText) v.findViewById(R.id.ed_ywmc3_day);
        ed_ywmc3_mg = (EditText) v.findViewById(R.id.ed_ywmc3_mg);

        ed_ywmc11 = v.findViewById(R.id.ed_ywmc11);
        ed_ywmc11_day = (EditText) v.findViewById(R.id.ed_ywmc11_day);
        ed_ywmc11_mg = (EditText) v.findViewById(R.id.ed_ywmc11_mg);
        ed_ywmc22 = v.findViewById(R.id.ed_ywmc22);
        ed_ywmc22_day = (EditText) v.findViewById(R.id.ed_ywmc22_day);
        ed_ywmc22_mg = (EditText) v.findViewById(R.id.ed_ywmc22_mg);
        ed_ywmc33 = v.findViewById(R.id.ed_ywmc33);
        ed_ywmc33_day = (EditText) v.findViewById(R.id.ed_ywmc33_day);
        ed_ywmc33_mg = (EditText) v.findViewById(R.id.ed_ywmc33_mg);

        ed_qtyw = (AutoCompleteTextView) v.findViewById(R.id.ed_qtyw);
        ed_qtyw_day = (EditText) v.findViewById(R.id.ed_qtyw_day);
        ed_qtyw_mg = (EditText) v.findViewById(R.id.ed_qtyw_mg);
        ed_zzyy = (EditText) v.findViewById(R.id.ed_zzyy);
        ed_jgkb = (EditText) v.findViewById(R.id.ed_jgkb);
        ed_xcsfsj = (EditTextWithDate) v.findViewById(R.id.ed_xcsfsj);
        nice_spinner_dw1 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw1);
        nice_spinner_dw2 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw2);
        nice_spinner_dw3 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw3);
        nice_spinner_dw11 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw11);
        nice_spinner_dw22 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw22);
        nice_spinner_dw33 = (NiceSpinner) v.findViewById(R.id.nice_spinner_dw33);
        nice_spinner_dwqt = (NiceSpinner) v.findViewById(R.id.nice_spinner_dwqt);
        ed_date.setBefore(true);
        ed_xcsfsj.setAfter(true, 0);

        // 创建一个ArrayAdapter，封装数组
        ArrayAdapter<String> arr = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_dropdown_item_1line,
                gxy_yws);

        ed_ywmc1.setAdapter(arr);
        ed_ywmc2.setAdapter(arr);
        ed_ywmc3.setAdapter(arr);
        ed_ywmc11.setAdapter(arr);
        ed_ywmc22.setAdapter(arr);
        ed_ywmc33.setAdapter(arr);
        ed_qtyw.setAdapter(arr);
        jieguo.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.daowei) {
                    isDaiWei = "1";
                } else if (checkedId == R.id.budaowei) {
                    isDaiWei = "2";
                }
            }
        });
    }

    /**
     * 绑定数据值
     *
     * @param str_where
     * @param flag
     * @author 王婷婷
     * @date 2015年12月17日 上午10:30:30
     */
    private void bindDdata(String flag, String str_where) {
        List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, str_where);
        if (flag.equals("症状")) {
            int size = listZZs.size();
            List<BD_DD_INFO> bd_zzs;
            if (size > 0) {
                bd_zzs = new ArrayList<BD_DD_INFO>();
                for (int i = 0; i < size; i++) {
                    String str_id = listZZs.get(i).getID();
                    if (str_id.equals("DM04-02_R42.x") || str_id.equals("DM04-02_H93.1")) {

                    } else {
                        bd_zzs.add(listZZs.get(i));
                    }
                }
                adapter_zz = new CheckBoxAdapter(getActivity(), bd_zzs);

            }
            gd_zz.setAdapter(adapter_zz);
        } else if (flag.equals("药物不良反应")) {
            adapter_ywblfy = new RadioButtonAdapter(listZZs, getActivity());
            adapter_ywblfy.setOtherMaxLength(50);
            gd_ywblfy.setAdapter(adapter_ywblfy);
        }

    }

    /**
     * 设置下拉
     *
     * @param flagName
     * @param strSql
     * @author 王婷婷
     * @date 2015年12月24日 上午9:19:28
     */

    private void bindSpinner(String flagName, String strSql) {
        List<BD_DD_INFO> sList = new ArrayList<BD_DD_INFO>();
        BD_DD_INFO bd = new BD_DD_INFO();
        bd.setDATAINFO("请选择");
        bd.setID("");
        sList.add(bd);

        List<BD_DD_INFO> sList1 = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                strSql + " order by cast(SORT as int) asc");
        sList.addAll(sList1);
        if (flagName.equals("摄盐")) {
            sy_list = sList;
            nice_spinner_syqk.attachDataSource(sy_list);

        } else if (flagName.equals("下次随访目标")) {
            xcsfmb_list = sList;
            nice_spinner_xcsfmb.attachDataSource(xcsfmb_list);

        } else if (flagName.equals("心理情况")) {

            int size = sList.size();
            if (size > 0) {
                xltz_list = new ArrayList<BD_DD_INFO>();
                zyxw_list = new ArrayList<BD_DD_INFO>();
                for (int i = 0; i < size; i++) {
                    String str_id = sList.get(i).getID();
                    if (str_id.equals("DM01-69_1") || str_id.equals("DM01-69_2") || str_id.equals("DM01-69_3")
                            || str_id.equals("")) {
                        xltz_list.add(sList.get(i));
                        zyxw_list.add(sList.get(i));
                    }
                }
            }

            nice_spinner_xltz.attachDataSource(xltz_list);
            nice_spinner_zyxw.attachDataSource(zyxw_list);
        } else if (flagName.equals("药物依从性")) {
            ywycx_list = sList;
            nice_spinner_fyycx.attachDataSource(ywycx_list);
        } else if (flagName.equals("此次随访分类")) {
            int size = sList.size();
            if (size > 0) {
                ccsffl_list = new ArrayList<BD_DD_INFO>();
                for (int i = 0; i < size; i++) {
                    String str_id = sList.get(i).getID();
                    if (str_id.equals("DM01-71_1") || str_id.equals("DM01-71_2") || str_id.equals("DM01-71_3")
                            || str_id.equals("DM01-71_4") || str_id.equals("")) {
                        ccsffl_list.add(sList.get(i));
                    }
                }
            }

            nice_spinner_clsffl.attachDataSource(ccsffl_list);

        } else if (flagName.equals("下一步管理措施")) {
//			List<String> ss = new ArrayList<String>();
//			ss.add("请选择");
//			ss.add("常规随访");
//			ss.add("第1次控制不满意2周随访");
//			ss.add("两次控制不满意转诊随访");
//			ss.add("紧急转诊");
//			nice_spinner_clsff2.attachDataSource(ss);
            ccsffl_list2 = sList;
            nice_spinner_clsff2.attachDataSource(ccsffl_list2);
        } else if (flagName.equals("随诊方式")) {
            szfs_list = sList;
            nice_spinner_szfs.attachDataSource(szfs_list);
        } else if (flagName.equals("药物单位")) {
            ywdw_list = sList1;
            nice_spinner_dw1.attachDataSource(sList1);
            nice_spinner_dw2.attachDataSource(sList1);
            nice_spinner_dw3.attachDataSource(sList1);
            nice_spinner_dw11.attachDataSource(sList1);
            nice_spinner_dw22.attachDataSource(sList1);
            nice_spinner_dw33.attachDataSource(sList1);
            nice_spinner_dwqt.attachDataSource(sList1);
        }

    }

    @Override
    public void setupView(View view) {

    }

    @Override
    public void addListener() {
        btn_choose_xy.setOnClickListener(this);
        btn_choose_tz.setOnClickListener(this);
        btn_choose_xl.setOnClickListener(this);
        changeBMI(ed_height, ed_tz, ed_tzzs);
        changeBMI(ed_height, ed_xcsfmb_tz, ed_tzzs_sf);
    }

    /**
     * 身高或者体重改变时，BMI的值随之发生改变
     **/
    private void changeBMI(final EditText etHeight, final EditText etWeight, final EditText etBMI) {
        etHeight.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (!TextUtils.isEmpty(etWeight.getText().toString())) {
                    setBMI(etHeight, etWeight, etBMI);
                } else {
                    etBMI.setText("");
                }

                if (TextUtils.isEmpty(s.toString())) {
                    etBMI.setText("");
                }

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        etWeight.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (!TextUtils.isEmpty(etHeight.getText().toString())) {
                    setBMI(etHeight, etWeight, etBMI);
                } else {
                    etBMI.setText("");
                }
                if (TextUtils.isEmpty(s.toString())) {
                    etBMI.setText("");
                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    /**
     * 设置BMI
     *
     * @author 王婷婷
     * @date 2017年4月5日 上午10:48:51
     */
    private void setBMI(EditText etHeight, EditText etWeight, EditText etBMI) {
        try {
            if (TextUtils.isEmpty(etHeight.getText().toString()) || TextUtils.isEmpty(etHeight.getText().toString())) {
                etBMI.setText("");
                return;
            }

            double dh = Double.parseDouble(etHeight.getText().toString()) / 100;
            double dw = Double.parseDouble(etWeight.getText().toString());

            java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");

            etBMI.setText(df.format(GlobalConts.getBMI(dh, dw)) + "");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    @Override
    public void setData() {
        try {

            // TODO
            bindDdata("症状", "PARENTID='DM04-02'");
            bindDdata("药物不良反应", "PARENTID='DM01-11'");

            bindSpinner("摄盐", "PARENTID='DM01-68'");
            bindSpinner("下次随访目标", "PARENTID='DM01-68'");
            bindSpinner("心理情况", "PARENTID='DM01-69'");
            bindSpinner("药物依从性", "PARENTID='DM01-70'");
            bindSpinner("此次随访分类", "PARENTID='DM01-71'");
            bindSpinner("随诊方式", "PARENTID='DM04-04'");
            bindSpinner("药物单位", "PARENTID='DM04-05'");
            bindSpinner("下一步管理措施", "PARENTID='DM04-13'");
            GlobalConts.doctorList(ed_sfys);
            setDBData();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private int fromCD_HY = 0;
    private int fromCD_DR = 0;
    private int fromCD_DR2 = 0;

    private void setDBData() {
        List<CD_HYPERTENSIONFOLLOWUP> list = new ArrayList<>();
        list = fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, strWhere);
        if (list.size() == 0) {
            list = fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, "IDCARD = '" + DEFAULT_IDCARD + "'");
            list.get(0).setIDCARD(NovaApplication.getUserInfo().getIDCARD());
            fromCD_HY = 0;
        } else {
            fromCD_HY = 1;
        }
        if (list.size() > 0) {

            readFollowup = list.get(0);
            ed_date.setDate(readFollowup.getFOLLOWUPDATE());
            for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
                if (NovaApplication.getDoctorList().get(i).getUSER_ID().equals(readFollowup.getFOLLOWUPDOCTOR())) {
                    ed_sfys.setSelectedIndex(i);
                    sfysqm.setText(NovaApplication.getDoctorList().get(i).getNAME());
                }
            }


            String symptoms = readFollowup.getSYMPTOM();
            adapter_zz.setChecked(symptoms);
            adapter_zz.setOther(readFollowup.getSYMPTOMOTHER());
            nice_spinner_szfs.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPWAY(), szfs_list));

            if (!TextUtils.isEmpty(readFollowup.getHYPERTENSION())) {
                if ((!TextUtils.isEmpty(readFollowup.getHYPERTENSION()))
                        && (!TextUtils.isEmpty(readFollowup.getHYPOTENSION()))) {
                }
                ed_xy.setText(notNull(readFollowup.getHYPERTENSION() + "/" + readFollowup.getHYPOTENSION()));
            }
            ed_xl.setText(notNull(readFollowup.getHEARTRATE()));
            ed_tz.setText(notNull(readFollowup.getWEIGHT()));
            ed_xcsfmb_tz.setText(notNull(readFollowup.getWEIGHTTARGET()));
            ed_tzzs.setText(notNull(readFollowup.getBMI()));
            ed_height.setText(notNull(readFollowup.getHeight()));
            ed_tzzs_sf.setText(notNull(readFollowup.getBMITARGET()));
            ed_qt.setText(notNull(readFollowup.getPHYSICALSYMPTOMOTHER()));

            ed_rxyl.setText(notNull(readFollowup.getDAILYSMOKENUM()));
            ed_xcsfmb_xy.setText(notNull(readFollowup.getDAILYSMOKENUMTARGET()));
            ed_ryjl.setText(notNull(readFollowup.getDAILYDRINKNUM()));
            ed_xcsfmb_yj.setText(notNull(readFollowup.getDAILYDRINKNUMTARGET()));
            ed_yd_zq.setText(notNull(readFollowup.getSPORTTIMEPERWEEK()));
            ed_yd_min.setText(notNull(readFollowup.getSPORTPERMINUTETIME()));
            ed_xcsfmb_yd_zq.setText(notNull(readFollowup.getSPORTTIMESPERWEEKTARGET()));
            ed_xcsfmb_yd_min.setText(notNull(readFollowup.getSPORTPERMINUTESTIMETARGET()));
            ed_fzjc.setText(readFollowup.getASSISTANTEXAM());
            System.out.println(readFollowup.getEATSALTTYPE() + "************");
            nice_spinner_syqk.setSelectedIndex(getListIndex(readFollowup.getEATSALTTYPE(), sy_list));
            nice_spinner_xcsfmb.setSelectedIndex(getListIndex(readFollowup.getEATSALTTARGET(), xcsfmb_list));
            nice_spinner_xltz.setSelectedIndex(getListIndex(readFollowup.getPSYCHOADJUSTMENT(), xltz_list));
            nice_spinner_zyxw.setSelectedIndex(getListIndex(readFollowup.getOBEYDOCTORBEHAVIOR(), zyxw_list));
            nice_spinner_clsffl.setSelectedIndex(getListIndex(readFollowup.getFOLLOWUPTYPE(), ccsffl_list));
            nice_spinner_clsff2.setSelectedIndex(getListIndex(readFollowup.getNextGLCS(), ccsffl_list2));
            nice_spinner_fyycx.setSelectedIndex(getListIndex(readFollowup.getMEDICATIONCOMPLIANCE(), ywycx_list));
            adapter_ywblfy.setChecked(readFollowup.getADR());
            adapter_ywblfy.setChecked(adapter_ywblfy.getChecked(), readFollowup.getADR_EX());
            ed_zzyy.setText(readFollowup.getREFERRALREASON());
            ed_jgkb.setText(readFollowup.getREFERRALORG());
            lxrdh.setText(readFollowup.getZZLXR());
            jmqm.setText(readFollowup.getHZQM());
            bz.setText(readFollowup.getBZ());

            if ("1".equals(readFollowup.getLXJG())) {
                daowei.setChecked(true);
            } else if ("2".equals(readFollowup.getLXJG())) {
                budaowei.setChecked(true);
            }

            if (readFollowup.getNEXTFOLLOWUPDATE() != null) {
                try {
                    ed_xcsfsj.setText(dateFormat.format(readFollowup.getNEXTFOLLOWUPDATE()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        } else {
            fromCD_HY = 0;
            ed_date.setText(dateFormat.format(new Date()));
            for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
                if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
                    ed_sfys.setSelectedIndex(i);
                    sfysqm.setText(NovaApplication.getDoctorList().get(i).getNAME());
                }

            }
        }
        // drugCondition1.setTYPE("1");
        // if (!TextUtils.isEmpty(medicine1)) {
        // drugCondition1.setNAME(medicine1);
        // drugCondition1.setDAILYTIME(getInt(count1));
        // drugCondition1.setEVERYTIMEMG(getInt(dose1));
        // fdbmanger.save(drugCondition1);
        // }
        List<CD_DRUGCONDITION> drugList = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class, strWhere + "AND TYPE = '1'");
        if (drugList.size() > 0) {
            fromCD_DR = 1;
            int size = drugList.size();
            EditText[] medicals = {ed_ywmc1, ed_ywmc2, ed_ywmc3, ed_qtyw};
            EditText[] times = {ed_ywmc1_day, ed_ywmc2_day, ed_ywmc3_day, ed_qtyw_day};
            EditText[] doses = {ed_ywmc1_mg, ed_ywmc2_mg, ed_ywmc3_mg, ed_qtyw_mg};

            for (int i = 0; i < size; i++) {
                CD_DRUGCONDITION drug = drugList.get(i);
                medicals[i].setText(notNull(drug.getNAME()));
                times[i].setText(notNull(drug.getDAILYTIME()));
                doses[i].setText(notNull(String.valueOf(drug.getEVERYTIMEMG())));
                if (i == 0) {
                    nice_spinner_dw1.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                } else if (i == 1) {
                    nice_spinner_dw2.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                } else if (i == 2) {
                    nice_spinner_dw3.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                } else if (i == 3) {
                    nice_spinner_dwqt.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                }
            }
        }
        List<CD_DRUGCONDITION> drugList2 = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class, strWhere + "AND TYPE = '11'");
        if (drugList2.size() > 0) {
            fromCD_DR2 = 1;
            int size = drugList2.size();
            EditText[] medicals = {ed_ywmc11, ed_ywmc22, ed_ywmc33, ed_qtyw};
            EditText[] times = {ed_ywmc11_day, ed_ywmc22_day, ed_ywmc33_day, ed_qtyw_day};
            EditText[] doses = {ed_ywmc11_mg, ed_ywmc22_mg, ed_ywmc33_mg, ed_qtyw_mg};

            for (int i = 0; i < size; i++) {
                CD_DRUGCONDITION drug = drugList2.get(i);
                medicals[i].setText(notNull(drug.getNAME()));
                times[i].setText(notNull(drug.getDAILYTIME()));
                doses[i].setText(notNull(String.valueOf(drug.getEVERYTIMEMG())));
                if (i == 0) {
                    nice_spinner_dw11.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                } else if (i == 1) {
                    nice_spinner_dw22.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                } else if (i == 2) {
                    nice_spinner_dw33.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                } else if (i == 3) {
                    nice_spinner_dwqt.setSelectedIndex(getListIndex(drug.getRES1(), ywdw_list));
                }
            }
        }
    }

    private int getListIndex(String str, List<BD_DD_INFO> bds) {
        if (str != null && !str.equals("")) {

            for (int i = 0; i < bds.size(); i++) {
                if (str.equals(bds.get(i).getID())) {
                    return i;
                }
            }
        }
        return 0;
    }

    private String notNull(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        return str;
    }

    public void save() {
        // 随诊方式
        String str_id = szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID();
        Log.w(TAG, "随诊方式：" + str_id);
        if (TextUtils.isEmpty(str_id)) {
            nice_spinner_szfs.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请选择随诊方式");
            return;
        } else {
            nice_spinner_szfs.setBackgroundColor(Color.WHITE);
        }

        // 症状
        String str_zz = adapter_zz.getCheckedIdsStr();
        if (TextUtils.isEmpty(str_zz)) {
            gd_zz.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请选择症状");
            return;
        } else {
            gd_zz.setBackgroundColor(Color.WHITE);
        }

        // 血压
        String str_xy = ed_xy.getText().toString();
        if (TextUtils.isEmpty(str_xy)) {
            ed_xy.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请填写血压");
            return;
        } else {
            if (!str_xy.contains("/")) {
                ed_xy.setBackgroundColor(Color.YELLOW);
                ((GXYActivity) getActivity()).showTextDialog("血压数据不合理，保存失败");
                return;
            } else {
                String[] split = str_xy.split("/");
                if (!GlobalConts.isRightNumber("血压", split[0])) {
                    ed_xy.setBackgroundColor(Color.YELLOW);
                    ((GXYActivity) getActivity()).showTextDialog("请输入正确的血压值");
                    return;
                } else if (!GlobalConts.isRightNumber("血压", split[1])) {
                    ed_xy.setBackgroundColor(Color.YELLOW);
                    ((GXYActivity) getActivity()).showTextDialog("请输入正确的血压值");
                    return;
                }
            }
            ed_xy.setBackgroundColor(Color.WHITE);
        }

        // 心率
        String str_xl = ed_xl.getText().toString();
        if (TextUtils.isEmpty(str_xl)) {
            ed_xl.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请输入心率");
            return;
        } else {
            ed_xl.setBackgroundColor(Color.WHITE);
            if (!GlobalConts.isRightNumber("脉率", str_xl)) {
                ed_xl.setBackgroundColor(Color.YELLOW);
                ((GXYActivity) getActivity()).showTextDialog("心率数据不合理，保存失败！");
                return;
            }
        }

        // 体重
        String str_tz = ed_tz.getText().toString();
        if (TextUtils.isEmpty(str_tz)) {
            ed_tz.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请输入体重");
            return;
        } else {
            ed_tz.setBackgroundColor(Color.WHITE);
            if (!GlobalConts.isRightNumber("体重", str_tz)) {
                ed_tz.setBackgroundColor(Color.YELLOW);
                ((GXYActivity) getActivity()).showTextDialog("体重数据不合理，保存失败！");
                return;
            }
        }

        // 身高
        String str_height = ed_height.getText().toString();
        if (TextUtils.isEmpty(str_height)) {
            ed_height.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请输入身高");
            return;
        } else {
            ed_height.setBackgroundColor(Color.WHITE);
            if (!GlobalConts.isRightNumber("身高", str_height)) {
                ed_height.setBackgroundColor(Color.YELLOW);
                ((GXYActivity) getActivity()).showTextDialog("身高数据不合理，保存失败！");
                return;
            }
        }
        // 体质指数
        String str_tzzs = ed_tzzs.getText().toString();
        if (TextUtils.isEmpty(str_tzzs)) {
            ed_tzzs.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请输入体质指数");
            return;
        } else {

            if (!GlobalConts.isRightNumber("体质指数", str_tzzs)) {
                ((GXYActivity) getActivity()).showTextDialog("请输入正确的身高或体重");
                return;
            }

        }

        String ed_tzzs_sf = ed_xcsfmb_tz.getText().toString();
        if (!TextUtils.isEmpty(ed_tzzs_sf)) {
            if (!GlobalConts.isRightNumber("体质指数", ed_tzzs_sf)) {
                ((GXYActivity) getActivity()).showTextDialog("请输入正确的身高或体重");
                return;
            }
        }


        // 下次随访时间
        String str_xcsfsj = ed_xcsfsj.getText().toString();

        if (TextUtils.isEmpty(str_xcsfsj)) {
            ed_xcsfsj.setBackgroundColor(Color.YELLOW);
            ((GXYActivity) getActivity()).showTextDialog("请选择下次随访时间");
            return;
        } else {
            ed_xcsfsj.setBackgroundColor(Color.WHITE);
        }

        followUp = new CD_HYPERTENSIONFOLLOWUP();
        saveBase();
        saveTizheng();
        saveLife();
        saveMedicine();
        //新增
        if (!TextUtils.isEmpty(lxrdh.getText())) {
            followUp.setZZLXR(lxrdh.getText().toString());
        }

        if (!TextUtils.isEmpty(jmqm.getText())) {
            followUp.setHZQM(jmqm.getText().toString());
        }
        if (!TextUtils.isEmpty(bz.getText())) {
            followUp.setBZ(bz.getText().toString());
        }

        followUp.setLXJG(isDaiWei);


        followUp.setIS_UPDATE("Y");
        followUp.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
        // List<CD_HYPERTENSIONFOLLOWUP> list =
        // fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class, strWhere);
        // if (list.size() > 0) {
        // for (CD_HYPERTENSIONFOLLOWUP info : list) {
        // fdbmanger.delete(info);
        // }
        // }
        followUp.setREFERRALREASON(ed_zzyy.getText().toString());
        followUp.setREFERRALORG(ed_jgkb.getText().toString());

        if (!TextUtils.isEmpty(str_xcsfsj)) {
            try {
                followUp.setNEXTFOLLOWUPDATE((Date) dateFormat.parse(str_xcsfsj));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        followUp.setLAST_UPDATE_DATE(new Date());
        followUp.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
        if (fromCD_HY == 1) {
            fdbmanger.updata(followUp, "IDCARD='" + userInfo.getIDCARD() + "'");
            followUp.setUPDATEORG(userInfo.getCREATEORG());
            followUp.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
            fdbmanger.updata(followUp);

        } else {
            followUp.setCREATED_BY(userInfo.getCREATED_BY());
            followUp.setCREATED_DATE(new Date());
            followUp.setCREATEORG(userInfo.getCREATEORG());
            followUp.setCREATER(userInfo.getCREATER());
            fdbmanger.save(followUp);
            fromCD_HY = 1;
        }
        // ((GXYActivity) getActivity()).showTextDialog("保存成功");
        Log.e(TAG, "tt" + NovaApplication.getType());
//		if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
//			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
//					.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//
//						@Override
//						public void onClick(DialogInterface dialog, int which) {
//							Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
//							intent.putExtra("type", "06");
//							intent.putExtra("szfs", szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
//							startActivity(intent);
//						}
//					}).show();
//		} else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
//			((GXYActivity) getActivity()).showTextDialog("保存成功");
//		}
        ((GXYActivity) getActivity()).showTextDialog("保存成功");
    }

    private void saveMedicine() {

        List<CD_DRUGCONDITION> drugList = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
                "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "' and TYPE='1'");
        List<CD_DRUGCONDITION> drugList2 = fdbmanger.findAllByWhere(CD_DRUGCONDITION.class,
                "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "' and TYPE='11'");
        for (CD_DRUGCONDITION drug : drugList) {
            fdbmanger.delete(drug);
        }
        for (CD_DRUGCONDITION drug : drugList2) {
            fdbmanger.delete(drug);
        }
        String medicine1 = ed_ywmc1.getText().toString();
        String count1 = ed_ywmc1_day.getText().toString();
        String dose1 = ed_ywmc1_mg.getText().toString();
        String medicine2 = ed_ywmc2.getText().toString();
        String count2 = ed_ywmc2_day.getText().toString();
        String dose2 = ed_ywmc2_mg.getText().toString();
        String medicine3 = ed_ywmc3.getText().toString();
        String count3 = ed_ywmc3_day.getText().toString();
        String dose3 = ed_ywmc3_mg.getText().toString();

        String medicine11 = ed_ywmc11.getText().toString();
        String count11 = ed_ywmc11_day.getText().toString();
        String dose11 = ed_ywmc11_mg.getText().toString();
        String medicine22 = ed_ywmc22.getText().toString();
        String count22 = ed_ywmc22_day.getText().toString();
        String dose22 = ed_ywmc22_mg.getText().toString();
        String medicine33 = ed_ywmc33.getText().toString();
        String count33 = ed_ywmc33_day.getText().toString();
        String dose33 = ed_ywmc33_mg.getText().toString();

        String otherMedicine = ed_qtyw.getText().toString();
        String otherCount = ed_qtyw_day.getText().toString();
        String otherDose = ed_qtyw_mg.getText().toString();

        CD_DRUGCONDITION drugCondition1 = new CD_DRUGCONDITION();
        CD_DRUGCONDITION drugCondition2 = new CD_DRUGCONDITION();
        CD_DRUGCONDITION drugCondition3 = new CD_DRUGCONDITION();
        CD_DRUGCONDITION drugCondition11 = new CD_DRUGCONDITION();
        CD_DRUGCONDITION drugCondition22 = new CD_DRUGCONDITION();
        CD_DRUGCONDITION drugCondition33 = new CD_DRUGCONDITION();


        CD_DRUGCONDITION drugCondition4 = new CD_DRUGCONDITION();

        drugCondition1.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
        drugCondition2.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
        drugCondition3.setIDCARD(NovaApplication.getUserInfo().getIDCARD());

        drugCondition11.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
        drugCondition22.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
        drugCondition33.setIDCARD(NovaApplication.getUserInfo().getIDCARD());

        drugCondition4.setIDCARD(NovaApplication.getUserInfo().getIDCARD());
        /** 类型 1高血压 2糖尿病 3精神疾病 4冠心病 5脑卒中  11高血压调整  12糖尿病调整*/
        drugCondition1.setTYPE("1");
        drugCondition2.setTYPE("1");
        drugCondition3.setTYPE("1");
        drugCondition11.setTYPE("11");
        drugCondition22.setTYPE("11");
        drugCondition33.setTYPE("11");


        drugCondition4.setTYPE("1");
        if (!TextUtils.isEmpty(medicine1)) {
            drugCondition1.setNAME(medicine1);
            drugCondition1.setDAILYTIME(count1);
            drugCondition1.setEVERYTIMEMG(dose1);
            drugCondition1.setRES1(ywdw_list.get(nice_spinner_dw1.getSelectedIndex()).getID());
            fdbmanger.save(drugCondition1);
        }
        if (!TextUtils.isEmpty(medicine2)) {
            drugCondition2.setNAME(medicine2);
            drugCondition2.setDAILYTIME(count2);
            drugCondition2.setEVERYTIMEMG(dose2);
            drugCondition2.setRES1(ywdw_list.get(nice_spinner_dw2.getSelectedIndex()).getID());
            fdbmanger.save(drugCondition2);
        }
        if (!TextUtils.isEmpty(medicine3)) {
            drugCondition3.setNAME(medicine3);
            drugCondition3.setDAILYTIME(count3);
            drugCondition3.setEVERYTIMEMG(dose3);
            drugCondition3.setRES1(ywdw_list.get(nice_spinner_dw3.getSelectedIndex()).getID());
            fdbmanger.save(drugCondition3);
        }

        if (!TextUtils.isEmpty(medicine11)) {
            drugCondition11.setNAME(medicine11);
            drugCondition11.setDAILYTIME(count11);
            drugCondition11.setEVERYTIMEMG(dose11);
            drugCondition11.setRES1(ywdw_list.get(nice_spinner_dw11.getSelectedIndex()).getID());
            fdbmanger.save(drugCondition11);
        }
        if (!TextUtils.isEmpty(medicine22)) {
            drugCondition22.setNAME(medicine22);
            drugCondition22.setDAILYTIME(count22);
            drugCondition22.setEVERYTIMEMG(dose22);
            drugCondition22.setRES1(ywdw_list.get(nice_spinner_dw22.getSelectedIndex()).getID());
            fdbmanger.save(drugCondition22);
        }
        if (!TextUtils.isEmpty(medicine33)) {
            drugCondition33.setNAME(medicine33);
            drugCondition33.setDAILYTIME(count33);
            drugCondition33.setEVERYTIMEMG(dose33);
            drugCondition33.setRES1(ywdw_list.get(nice_spinner_dw33.getSelectedIndex()).getID());
            fdbmanger.save(drugCondition33);
        }
        if (!TextUtils.isEmpty(otherMedicine)) {
            drugCondition4.setNAME(otherMedicine);
            drugCondition4.setDAILYTIME(otherCount);
            drugCondition4.setEVERYTIMEMG(otherDose);
            drugCondition4.setRES1(ywdw_list.get(nice_spinner_dwqt.getSelectedIndex()).getID());
            fdbmanger.save(drugCondition4);
        }

    }

    private void saveLife() {

        String fuzhuJiancha = ed_fzjc.getText().toString();

        followUp.setDAILYSMOKENUM(ed_rxyl.getText().toString());
        followUp.setDAILYDRINKNUM(ed_ryjl.getText().toString());
        followUp.setDAILYDRINKNUMTARGET(ed_xcsfmb_yj.getText().toString());
        followUp.setDAILYSMOKENUMTARGET(ed_xcsfmb_xy.getText().toString());
        followUp.setSPORTTIMEPERWEEK(ed_yd_zq.getText().toString());
        followUp.setSPORTTIMESPERWEEKTARGET(ed_xcsfmb_yd_zq.getText().toString());
        followUp.setSPORTPERMINUTESTIMETARGET(ed_xcsfmb_yd_min.getText().toString());
        followUp.setSPORTPERMINUTETIME(ed_yd_min.getText().toString());
        followUp.setASSISTANTEXAM(fuzhuJiancha);
        followUp.setEATSALTTYPE(sy_list.get(nice_spinner_syqk.getSelectedIndex()).getID());
        followUp.setEATSALTTARGET(xcsfmb_list.get(nice_spinner_xcsfmb.getSelectedIndex()).getID());
        Log.e("随诊方式---此次随访分了-6666------", xcsfmb_list.get(nice_spinner_xcsfmb.getSelectedIndex()).getID());
        followUp.setPSYCHOADJUSTMENT(xltz_list.get(nice_spinner_xltz.getSelectedIndex()).getID());
        followUp.setOBEYDOCTORBEHAVIOR(zyxw_list.get(nice_spinner_zyxw.getSelectedIndex()).getID());
        followUp.setMEDICATIONCOMPLIANCE(ywycx_list.get(nice_spinner_fyycx.getSelectedIndex()).getID());
        Log.e("随诊方式---此次随访分了-------", ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID());
        followUp.setFOLLOWUPTYPE(ccsffl_list.get(nice_spinner_clsffl.getSelectedIndex()).getID());

        followUp.setNextGLCS(ccsffl_list2.get(nice_spinner_clsff2.getSelectedIndex()).getID());
        String checked = adapter_ywblfy.getChecked();
        followUp.setADR(checked);
        followUp.setADR_EX(adapter_ywblfy.getCheckedOther());

    }

    private void saveTizheng() {
        String et_other = ed_qt.getText().toString();
        String str_xy = ed_xy.getText().toString();
        if (!TextUtils.isEmpty(str_xy)) {
            if (str_xy.contains("/")) {
                if (str_xy.split("/").length == 2) {
                    followUp.setHYPERTENSION(str_xy.split("/")[0]);// 收缩压
                    followUp.setHYPOTENSION(str_xy.split("/")[1]);// 舒张压
                } else {
                    followUp.setHYPERTENSION("");// 收缩压
                    followUp.setHYPOTENSION("");// 舒张压
                }
            } else {
                followUp.setHYPERTENSION("");// 收缩压
                followUp.setHYPOTENSION("");// 舒张压
            }
        } else {
            followUp.setHYPERTENSION("");// 收缩压
            followUp.setHYPOTENSION("");// 舒张压
        }
        // followUp.setHYPERTENSION(120);
        // followUp.setHYPOTENSION(80);
        followUp.setWEIGHT(ed_tz.getText().toString());
        followUp.setHeight(ed_height.getText().toString());
        followUp.setBMI(ed_tzzs.getText().toString());
        followUp.setHEARTRATE(ed_xl.getText().toString());
        followUp.setWEIGHTTARGET(ed_xcsfmb_tz.getText().toString());
        followUp.setBMITARGET(ed_tzzs_sf.getText().toString());
        followUp.setPHYSICALSYMPTOMOTHER(et_other);
    }

    private void saveBase() {
        Date edDate = ed_date.getDate();

        followUp.setFOLLOWUPDATE(edDate);
        followUp.setSYMPTOM(adapter_zz.getCheckedIdsStr());
        followUp.setSYMPTOMOTHER(adapter_zz.getOther());
        Log.e("tag", adapter_zz.getOther());
        followUp.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
        Log.e("随诊方式----------", szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
        followUp.setFOLLOWUPWAY(szfs_list.get(nice_spinner_szfs.getSelectedIndex()).getID());
        followUp.setUPDATEORG(NovaApplication.getUserInfo().getCREATEORG());
        followUp.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfys.getSelectedIndex()).getUSER_ID());
    }

    @Override
    public void onClick(View v) {

        Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
        int id = v.getId();
        if (id == R.id.btn_choose_xy) {
            intent.putExtra("flag", BluetoothConstant.XUEYA_TYPENAME);
            getActivity().startActivityForResult(intent, GlobalConts.RequestXueya);
        } else if (id == R.id.btn_choose_tz) {
            intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
            getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
        } else if (id == R.id.btn_choose_xl) {
            intent.putExtra("flag", "心率");
            getActivity().startActivityForResult(intent, GlobalConts.RequestMaiLv);
        } else {
        }
    }

    @Override
    public void setXueya(String gaoya, String diya, String mailv) {
        if (!TextUtils.isEmpty(gaoya) && !TextUtils.isEmpty(diya)) {
            ed_xy.setText(gaoya + "/" + diya);
        }

    }

    @Override
    public void setTizhong(String value) {
        ed_tz.setText(value);

    }

    @Override
    public void setMaiLv(String mailv) {
        ed_xl.setText(mailv);
    }
}
